<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>个人信息 - 教师端</title>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/css/all.min.css">
    <style>
        body, html { min-height: 100vh; height: 100%; margin: 0; padding: 0; display: flex; flex-direction: column; }
        body { background-color: #f5f7fb; flex: 1 0 auto; }
        /* 导航栏样式与首页一致 */
        .navbar {
            background: linear-gradient(135deg, #4361ee, #3f37c9);
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 0.8rem 1rem;
        }
        .navbar-brand {
            font-weight: 700;
            font-size: 1.5rem;
            display: flex;
            align-items: center;
        }
        .navbar-brand i {
            margin-right: 10px;
            font-size: 1.8rem;
        }
        .nav-link {
            color: rgba(255, 255, 255, 0.85) !important;
            font-weight: 500;
            padding: 0.5rem 1rem !important;
            border-radius: 4px;
            margin: 0 3px;
            transition: all 0.3s ease;
        }
        .nav-link:hover, .nav-link.active {
            background-color: rgba(255, 255, 255, 0.15);
            color: white !important;
        }
        .profile-card {
            background: #fff;
            border-radius: 16px;
            box-shadow: 0 4px 20px rgba(67,97,238,0.10);
            padding: 2.5rem 2.5rem 2rem 2.5rem;
            max-width: 700px;
            margin: 3rem auto 2rem auto;
            flex: 1 0 auto;
        }
        .profile-title {
            font-weight: 700;
            font-size: 1.5rem;
            text-align: center;
            margin-bottom: 0.5rem;
        }
        .profile-role {
            text-align: center;
            color: #4361ee;
            font-weight: 500;
            margin-bottom: 1.5rem;
        }
        .btn-primary {
            background: linear-gradient(135deg, #4361ee, #3a0ca3);
            border: none;
            border-radius: 8px;
            font-weight: 600;
        }
        .btn-primary:hover {
            background: #3f37c9;
        }
        .btn-secondary {
            border-radius: 8px;
            font-weight: 600;
        }
        .form-control, .form-select {
            border-radius: 8px;
            box-shadow: none;
            border: 1px solid #e0e7ff;
        }
        .form-control:focus, .form-select:focus {
            border-color: #4361ee;
            box-shadow: 0 0 0 2px #e0e7ff;
        }
        .footer {
            background: linear-gradient(135deg, #4361ee, #3f37c9);
            color: white;
            padding: 2rem 0 1rem 0;
            flex-shrink: 0;
        }
        .footer .copyright {
            text-align: center;
            color: rgba(255,255,255,0.8);
            font-size: 0.95rem;
            margin-top: 0.5rem;
        }
        .footer a {
            color: #fff;
            font-size: 1.7rem;
            margin: 0 8px;
            transition: color 0.2s;
        }
        .footer a:hover {
            color: #ffd700;
        }
    </style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark" style="background: linear-gradient(135deg, #4361ee, #3f37c9);">
    <div class="container">
        <a class="navbar-brand" href="/home/manage"><i class="fas fa-chalkboard-teacher"></i> 在线考试系统</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav me-auto">
                <li class="nav-item">
                    <a class="nav-link" href="/home/manage"><i class="fas fa-home"></i> 主页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/exam/manage"><i class="fas fa-tasks"></i> 考试管理</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/teacher/question/manage"><i class="fas fa-book"></i> 题库管理</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/teacher/score/analysis"><i class="fas fa-chart-bar"></i> 成绩分析</a>
                </li>
            </ul>
            <ul class="navbar-nav ms-auto">
                <li class="nav-item">
                    <a class="nav-link active" href="/teacher/profile"><i class="fas fa-user-circle"></i> 个人信息</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/logout"><i class="fas fa-sign-out-alt"></i> 退出登录</a>
                </li>
            </ul>
        </div>
    </div>
</nav>
<div class="profile-card">
    <div class="profile-title mb-2"><i class="fas fa-user-circle me-2"></i>教师个人信息</div>
    <div class="profile-role mb-4">系统教师</div>
    <form id="profileForm">
        <div class="row g-3 mb-3">
            <div class="col-md-6">
                <label class="form-label">姓名</label>
                <input type="text" class="form-control" th:value="${user.realName}" readonly>
            </div>
            <div class="col-md-6">
                <label class="form-label">用户名</label>
                <input type="text" class="form-control" th:value="${user.userName}" readonly>
            </div>
        </div>
        <div class="row g-3 mb-3">
            <div class="col-md-6">
                <label class="form-label">邮箱</label>
                <input type="email" class="form-control" id="email" name="email" th:value="${user.email}" required>
            </div>
            <div class="col-md-6">
                <label class="form-label">手机号</label>
                <input type="text" class="form-control" id="phone" name="phone" th:value="${user.phone}">
            </div>
        </div>
        <div class="mb-4">
            <label class="form-label">教授课程/班级</label>
            <div class="card bg-white shadow-sm p-3" style="border-radius: 10px; min-height: 48px;">
                <div class="row">
                    <div class="col-md-6 mb-2 mb-md-0">
                        <span style="font-weight:600;color:#4361ee;">课程：</span>
                        <ul id="courseList" class="mb-0" style="list-style:none;padding-left:0;display:inline;"></ul>
                    </div>
                    <div class="col-md-6">
                        <span style="font-weight:600;color:#4361ee;">班级：</span>
                        <ul id="classList" class="mb-0" style="list-style:none;padding-left:0;display:inline;"></ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="text-center mt-4">
            <button type="submit" class="btn btn-primary px-4">保存修改</button>
            <a href="/home/manage" class="btn btn-secondary ms-3 px-4">返回首页</a>
        </div>
    </form>
</div>
<!-- 页脚 -->
<footer class="footer">
    <div class="container text-center py-4">
        <a href="https://gitee.com/sorrymaker04/onlineexam-workload" target="_blank"><i class="fab fa-github fa-2x"></i></a>
        <div class="copyright mt-2">
            &copy; 2025 版权所有 北城在线考试系统小组 12 Team
        </div>
    </div>
</footer>
<script src="/js/axios.min.js"></script>
<script src="/js/bootstrap.bundle.min.js"></script>
<script>
    // 加载课程班级信息
    window.onload = function() {
        axios.get('/teacher/profile/info').then(function(res) {
            const data = res.data;
            const courseList = document.getElementById('courseList');
            const classList = document.getElementById('classList');
            courseList.innerHTML = '';
            classList.innerHTML = '';
            if (data.success) {
                if (data.courses && data.courses.length > 0) {
                    data.courses.forEach(function(c, idx) {
                        const li = document.createElement('li');
                        li.style.display = 'inline';
                        li.innerHTML = `<span style='color:#3f37c9;'>${c.course_name || c.courseName}</span>` + (idx < data.courses.length-1 ? '、' : '');
                        courseList.appendChild(li);
                    });
                } else {
                    courseList.innerHTML = '<li style="color:#aaa;display:inline;">暂无课程</li>';
                }
                if (data.classes && data.classes.length > 0) {
                    data.classes.forEach(function(c, idx) {
                        const li = document.createElement('li');
                        li.style.display = 'inline';
                        li.innerHTML = `<span style='color:#3f37c9;'>${c.class_name || c.className}</span>` + (idx < data.classes.length-1 ? '、' : '');
                        classList.appendChild(li);
                    });
                } else {
                    classList.innerHTML = '<li style="color:#aaa;display:inline;">暂无班级</li>';
                }
            } else {
                courseList.innerHTML = '<li style="color:#aaa;display:inline;">暂无课程</li>';
                classList.innerHTML = '<li style="color:#aaa;display:inline;">暂无班级</li>';
            }
        });
    };
    // 保存修改
    document.getElementById('profileForm').onsubmit = function(e) {
        e.preventDefault();
        const email = document.getElementById('email').value;
        const phone = document.getElementById('phone').value;
        axios.post('/teacher/profile/update', new URLSearchParams({email, phone}))
            .then(function(res) {
                if (res.data === 'success') {
                    alert('保存成功！');
                    location.reload();
                } else {
                    alert(res.data);
                }
            });
    };
</script>
</body>
</html> 